define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var array = require("$UI/system/lib/base/array");
	var Model = function(){
		this.callParent();
	};
	
	Model.prototype.Phone = function(row){
		var LoginState = localStorage.getItem('LoginState');
		return row.val('fPhone')== LoginState;
	};
	
	Model.prototype.getTexts = function(){
		  var data = this.comp('harvestData');
		  var LoginState = localStorage.getItem('LoginState');
		  var ret = [];
		  var tmp = [];
		  var j = 0;
		   justep.Baas.sendRequest({
			"url" : "/nase/nase_action",
			"action" : "queryNase_harvest",
			"async" : false,
			"params" : {},
			"success" : function(data) {
				array.each(data.rows, function(obj) {
				var fPhone = obj.fPhone.value;
				if(LoginState == fPhone){
						var fCommon = obj.fCommon.value;
						tmp[j]=fCommon;
						j=j+1;
					}
				});
			}
		   });
		  var max = tmp[0];
		  for(var i=1;i<tmp.length;i++){ 
			  if(max<tmp[i])max=tmp[i];}
		   data.each(function(param){
			   var row = param.row;
			   var fPhone = row.val('fPhone');
			   if(LoginState == fPhone){
				    var fCommon = row.val('fCommon')||'';
				    if(fCommon == max) ret.push(row);
			    }
			  });
		   return ret;
	};
	Model.prototype.newClick = function(event){
this.comp("windowDialog1").open({params:{operator:'new'
}});
		};
		
	Model.prototype.button3Click = function(event){
	var row = event.bindingContext.$object;
this.comp("windowDialog1").open({
	params:{
	operator:'edit',
	rowdata:row.toJson()
	} 
	});
	};
		
	Model.prototype.windowDialog1Received = function(event){
this.comp("harvestData").saveData();
	};
		
	Model.prototype.button4Click = function(event){
var row = event.bindingContext.$object;
this.comp("harvestData").deleteData(row);
	};
		
	Model.prototype.modelParamsReceive = function(event){
this.comp("harvestData").saveData();
	};
		
	return Model;
});